@model LoginViewModel
@inject SignInManager<UserEntity> SignInManager

@{
    Layout = "~/Views/Shared/_Root.cshtml";
    ViewData["Title"] = Localizer["Log in"];
}

<div id="content">
    <div id="logo">
        <svg version="1.1" id="layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
             width="150px" height="150px" viewBox="0 0 150 150" enable-background="new 0 0 150 150" xml:space="preserve">
        <g>
        <path fill="#249CD9" d="M14.862,108.752c0-4.834,0-9.668,0-14.502c2.822,0.234,5.724,0.218,8.559,0.177
		        c2.837-0.044,5.373-0.032,7.792,0.031c2.417,0.061,4.618,0.204,6.768,0.314c2.144,0.112,4.067,0.171,5.826,0.027
		        c6.028-0.435,10.388-1.677,13.179-4.178c2.777-2.453,4.052-5.926,3.372-10.728c-0.353-2.55-1.283-4.832-2.643-6.819
		        c-1.354-1.983-2.979-3.735-4.588-5.159c-1.619-1.428-3.146-2.575-4.578-3.457c-1.45-0.889-2.726-1.577-4.385-2.292
		        c-1.752-0.756-3.808-1.569-6.548-2.771c-2.721-1.193-5.978-2.878-9.351-5.172c-3.367-2.28-6.686-5.242-9.216-8.649
		        c-2.56-3.401-3.925-7.31-3.912-11.205c-0.02-4.82,1.965-8.03,4.592-10.464c2.652-2.441,5.333-4.632,8.323-7.094
		        c2.996-2.416,6.258-5.136,10.343-7.215c4.056-2.092,8.541-3.413,13.09-3.384c10.466,0.021,17.306,2.74,22.098,4.72
		        c-0.637,5.697-1.186,10.913-1.648,15.778c-8.079-0.623-14.598-1.054-22.431-0.424c-2.144,0.167-4.254,0.583-6.333,1.178
		        c-2.082,0.593-3.896,1.489-5.464,2.618c-1.568,1.131-2.814,2.525-3.735,4.197c-0.923,1.668-1.239,3.832-0.862,6.462
		        c0.342,2.442,1.123,4.57,2.261,6.414c1.13,1.841,2.595,3.52,4.125,4.93c1.534,1.414,3.075,2.618,4.516,3.564
		        c1.464,0.956,2.79,1.733,4.45,2.46c1.713,0.754,3.634,1.498,6.324,2.659c2.668,1.153,5.949,2.813,9.487,5.187
		        c3.526,2.358,7.108,5.457,9.909,9.025c2.831,3.565,4.36,7.607,4.331,11.506c0.003,5.219-1.935,8.666-4.471,11.199
		        c-2.572,2.538-5.247,4.762-8.28,7.189c-3.042,2.382-6.408,5.009-10.644,6.861c-4.208,1.866-8.97,3.049-13.959,3.021
		        c-1.661,0.003-3.696-0.292-6.067-0.795c-2.375-0.502-4.742-1.186-7.158-1.875c-2.42-0.69-4.711-1.382-7.028-1.935
		        C18.59,109.598,16.558,109.184,14.862,108.752z" />
        </g>
        <g>
        <path fill="#249CD9" d="M134.32,52.104c-19.58,9.17-25.526,11.286-38.813,6.349c2.111,16.338,3.296,24.661,3.554,32.006
		        c11.717,1.458,7.017,0.989,29.287-1.405c-0.039,3.242-0.035,6.456,0.012,9.704c-22.234-2.836-17.601-3.391-29.32-1.665
		        c-0.393,9.475-2.304,20.856-5.734,48.908c-4.102,0-8.203,0-12.305,0c0-35.01,0-70.02,0-105.029c17.773,0,35.547,0,53.32,0
		        C134.32,44.682,134.32,48.393,134.32,52.104z" />
        </g>
        </svg>
    </div>
    <div id="content-box" class="clearfix">
        <div id="zone-main" class="zone-instance">
            <div class="zone-content">
                <div data-zone-location="Page" class="block-instance login">
                    <div class="block-content">
                        <form asp-controller="Account" asp-action="Login" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post">
                            <fieldset>
                                <legend>Login</legend>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="login_tips alert alert-danger" style="display:none">
                                        </div>
                                        <div asp-validation-summary="All" class="text-danger"></div>
                                        <div class="form-group rock-text-box">
                                            <label class="control-label" asp-for="Email">@Localizer["Email"]</label>
                                            <div class="control-wrapper">
                                                <input asp-for="Email" class="form-control">
                                            </div>
                                            <span class="validation-error help-inline" style="display:none">Username is Required.</span>
                                        </div>
                                        <div class="form-group rock-text-box">
                                            <label class="control-label" asp-for="Password">@Localizer["Password"]</label>
                                            <div class="control-wrapper">
                                                <input type="hidden" name="tbPassword_dvrm" id="tbPassword_dvrm" value="True">
                                                <input asp-for="Password" class="form-control" autocomplete="off" value="">
                                            </div>
                                            <span class="validation-error help-inline" style="display:none">Password is Required.</span>
                                        </div>
                                        <div class="checkbox">
                                            <label><input asp-for="RememberMe">@Localizer["Remember me?"]</label>
                                        </div>
                                        <input type="submit" value="@Localizer["Log in"]" id="btnlogin" class="btn btn-primary">
                                        <a href="/Account/ForgotPassword" id="btnHelp" class="btn btn-link">@Localizer["Forgot your password?"]</a>
                                    </div>
                                </div>
                            </fieldset>
                        </form>
                    </div>
                </div>
                <div data-zone-location="Page" class="block-instance html-content">
                    <div class="block-content">
                        <div class="alert alert-info margin-t-lg">
                            <strong>Demo Account</strong> To login as a demo administrator use the username 'administrator' with the password of '123456'.
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    var contentPath = '@Url.Content("~")'.substr(0, '@Url.Content("~")'.length - 1);
    var returnUrl = '@ViewData["ReturnUrl"]';
    //回车键
    document.onkeydown = function (e) {
        if (!e) e = window.event;
        if ((e.keyCode || e.which) == 13) {
            var btlogin = document.getElementById("btnlogin");
            btnlogin.click();
        }
    }
    // add quick fade-in effect to the page
    $(document).ready(function () {
        $("body").attr("id", "splash");
        $("#content").sfFadeIn();
        //错误提示
        if (top.$.cookie('learun_login_error') != null) {
            switch (top.$.cookie('learun_login_error')) {
                case "Overdue":
                    formMessage('登录已超时,请重新登录');
                    break;
                case "OnLine":
                    formMessage('您的帐号已在其它地方登录,请重新登录');
                    break;
                case "-1":
                    formMessage('未知错误,请重新登录');
                    break;
                default:
                    break;
            }
            top.$.cookie('learun_login_error', '', { path: "/", expires: -1 });
        }
        //是否自动登录
        if (top.$.cookie('learn_autologin') == 1) {
            $("#autologin").attr("checked", 'true');
            $("#Email").val(top.$.cookie('learn_username'));
            $("#Password").val(top.$.cookie('learn_password'));
            CheckLogin(1);
        }
        //设置下次自动登录
        $("#RememberMe").click(function () {
            if (!$(this).attr('checked')) {
                $(this).attr("checked", 'true');
                top.$.cookie('learn_autologin', 1, { path: "/", expires: 7 });
            } else {
                $(this).removeAttr("checked");
                top.$.cookie('learn_autologin', '', { path: "/", expires: -1 });
                top.$.cookie('learn_username', '', { path: "/", expires: -1 });
                top.$.cookie('learn_password', '', { path: "/", expires: -1 });
            }
        })
        //登录按钮事件
        $("#btnlogin").click(function () {
            var $username = $("#Email");
            var $password = $("#Password");
            //var $verifycode = $("#verifycode");
            if ($username.val() == "") {
                $username.focus();
                formMessage('请输入账户或手机号或邮箱。');
                return false;
            } else if ($password.val() == "") {
                $password.focus();
                formMessage('请输入密码。');
                return false;
            }
                // else if ($verifycode.val() == "") {
                //    $verifycode.focus();
                //    formMessage('请输入验证码。');
                //    return false;
                //}
            else {
                CheckLogin(0);
            }
        });
        //点击切换验证码
        $("#login_verifycode").click(function () {
            $("#verifycode").val('');
            $("#login_verifycode").attr("src", contentPath + "/Login/VerifyCode?time=" + Math.random());
        });
    });
    //登录验证
    function CheckLogin(autologin) {
        $("#btnlogin").addClass('active').attr('disabled', 'disabled');
        $("#btnlogin").find('span').hide();

        var username = $.trim($("#Email").val());
        var password = $.trim($("#Password").val());
        var verifycode = "";// $.trim($("#verifycode").val());
        if (top.$.cookie('learn_password') == "" || top.$.cookie('learn_password') == null) {
            // password = $.md5(password);
        }
        SF.utility.loading(true);
        $.ajax({
            url: contentPath + "/Login",
            data: { Email: $.trim(username), password: $.trim(password), verifycode: verifycode, rememberMe: autologin, returnUrl: "" },
            type: "post",
            dataType: "json",
            success: function (data) {
                if (data.state == "success") {
                    if (top.$.cookie('learn_autologin') == 1) {
                        top.$.cookie('learn_username', $.trim(username), { path: "/", expires: 7 });
                        top.$.cookie('learn_password', $.trim(password), { path: "/", expires: 7 });
                    }
                    if (returnUrl == "")
                        window.location.href = contentPath == "" ? '/' : contentPath;
                    else
                        window.location.href = returnUrl;
                } else {
                    if (data.message.length >= 30) {
                        SF.dialogs.alert(data.message)
                    } else {
                        formMessage(data.message);
                    }
                    $("#btnlogin").removeClass('active').removeAttr('disabled');
                    $("#btnlogin").find('span').show();
                    $("#login_verifycode").trigger("click");
                }
                SF.utility.loading(false);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //通常情况下textStatus和errorThrown只有其中一个包含信息
                //调用本次ajax请求时传递的options参数
                var data = JSON.parse(XMLHttpRequest.responseText);
                formMessage(data.message);
                $("#btnlogin").removeClass('active').removeAttr('disabled');
                $("#btnlogin").find('span').show();
                SF.utility.loading(false);
            }
        });
    }
    //提示信息
    function formMessage(msg, type) {
        $('.login_tips').html("");
        $('.login_tips').prepend(msg);
        $('.login_tips').addClass("alert-danger");
        if (type == "success") {
            $('.login_tips').removeClass("alert-success");
        }
        $('.login_tips').show();
    }
</script>
 